/* Description Panel */
$("#game-description").expandable({
    expandButton:"#game-description .expand-button",
    contentPanel:"#game-description .content",
    minHeight:150
});
document.addEventListener('DOMContentLoaded', function(){
    screenShot = new iScroll('item-screenshot-slider', {
        useTransform: false,
        hScrollbar: false,
        vScrollbar: false,
        onBeforeScrollStart: function (e) {
            var target = e.target;
            while (target.nodeType != 1) target = target.parentNode;

            if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA')
                e.preventDefault();
        }
    });
}, false);
$("body").everyTime(1000, function (i) {
    $('#item-screenshot-slider').children().autoWidth({
        margin: 30
    });
    screenShot.refresh();
}, 1);
function loadAutoComments(){
    if(typeof commentCurrentPage === 'undefined'){
        commentCurrentPage = 1;
    }
    $("#comment-list").loadComments({
        id: $("#item-id").val(),
        page: commentCurrentPage,
        container: $("#comment-list"),
        next: $("#comment-next-btn"),
        prev: $("#comment-prev-btn")
    });
}
$("#comment-list").everyTime(5000, function (i) {
    loadAutoComments();
}, 0);
document.addEventListener('DOMContentLoaded', loadAutoComments, false);
$("#comment-next-btn").click(function(){
    if(commentCurrentPage < commentPageCount){    
        var nextPage = parseInt(commentCurrentPage) + 1;
        $("#comment-list").loadComments({
            id: $("#item-id").val(),
            page: nextPage,
            container: $("#comment-list"),
            next: $("#comment-next-btn"),
            prev: $("#comment-prev-btn")
        });
    }
    return false;
});
$("#comment-prev-btn").click(function(){
    if(commentCurrentPage > 1){
        var prevPage = parseInt(commentCurrentPage) - 1;
        $("#comment-list").loadComments({
            id: $("#item-id").val(),
            page: prevPage,
            container: $("#comment-list"),
            next: $("#comment-next-btn"),
            prev: $("#comment-prev-btn")
        });
    }
    return false;
});
$("#btn-send").click(function(){
    $("#btn-send").sendComment({
        id: $("#item-id").val(),
        content: $("#txt-comment"),
        page: 1,
        container: $("#comment-list"),
        next: $("#comment-next-btn"),
        prev: $("#comment-prev-btn"),
        locale: $("#locale").val()
    }); 
});
$("#txt-comment").keydown(function(e){
    // Enter was pressed without shift key
    if (e.keyCode == 13 && !e.shiftKey){
        // prevent default behavior
        $("#txt-comment").sendComment({
            id: $("#item-id").val(),
            content: $("#txt-comment"),
            page: 1,
            container: $("#comment-list"),
            next: $("#comment-next-btn"),
            prev: $("#comment-prev-btn"),
            locale: $("#locale").val()
        });
        e.preventDefault();
    }
});